package com.study.listener;

import com.study.domain.TMqttMsg;
import com.study.event.MqttMsgEvent;
import com.study.service.TMqttMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author csc
 * @version 1.0.0
 * @create 2024/12/27 11:34
 * @Descriotion: 监听器
 */
@Component
public class MqttEventListener {

    @Autowired
    private TMqttMsgService mqttMsgService;


    /**
     {
     "mqtt_receivedRetained": true,
     "mqtt_id": 0,
     "mqtt_duplicate": false,
     "id": "5c396b63-5fb0-576f-4d9a-2b0506d81c29",
     "mqtt_receivedTopic": "/yy",
     "mqtt_receivedQos": 0,
     "timestamp": 1735614974371
     }
     * @param event
     */
    @Async
    @EventListener
    public void handleCustomEvent(MqttMsgEvent event) {
        TMqttMsg covert = TMqttMsg.covert(event.getMessage());
        //保存
        mqttMsgService.save(covert);

    }




}
